package ru.vsu.cs.pm.models;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import ru.vsu.cs.pm.beans.DealerShipManager;

/**
 * User: ohodyakov
 * Date: 04.01.2011
 * Time: 12:34:31
 */
public class DealerShipModel extends LoadableDetachableModel<DealerShip> {

    @SpringBean
    private DealerShipManager dealerShipManager;

    private Integer id;

    public DealerShipModel() {
        InjectorHolder.getInjector().inject(this);
    }

    public DealerShipModel(Integer id) {
        this.id = id;
        InjectorHolder.getInjector().inject(this);
    }

    public DealerShipModel(DealerShip item) {
        super(item);
        this.id = item.getId();
        InjectorHolder.getInjector().inject(this);
    }

    @Override
    protected DealerShip load() {
        if(id == null) {
            return new DealerShip();
        }
        return dealerShipManager.getDealerShip(id);
    }
}